from telnetlib import EC
from time import sleep

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

from Until.until import find_element, find_elements

chromeDriver_path = 'E:\Python\chromedriver.exe'
options = Options()
options.add_argument('--start-maximized')

wd = webdriver.Chrome(executable_path=chromeDriver_path,options=options)
wd.get('http://www.cherryzqr.top/fsmarket/index.php')

# find_element(wd,'link text','会员登录').click()
# find_element(wd,'id','username').send_keys('cherry1')
# find_element(wd,'id','password').send_keys('123456')
# find_element(wd,'name','submit').click()

find_element(wd,'name','keywords').send_keys('牛奶')
find_element(wd,'id','searchBtn').click()
sleep(2)
find_element(wd,'class name','sales').click()
new_windows = wd.window_handles[-1]
wd.switch_to.window(new_windows)
sleep(1)
find_element(wd,'id','nowbuy').click()
sleep(1)
find_element(wd,'class name','btn').click()
find_element(wd,'class name','flow_btn').click()
find_element(wd,'id','username').send_keys('cherry1')
find_element(wd,'id','password').send_keys('123456')
find_element(wd,'name','submit').click()
sleep(5)
find_element(wd,'class name','btn').click()


# wd.find_elements_by_class_name('checkout-item')[1].click()

# wd.find_elements(by='class name',value='checkout-item')[1].click()

find_elements(wd,'class name','checkout-item')[1].click()
sleep(1)
find_element(wd,'id','act_3').click()



# move = find_element(wd,'class name','cart-mini')  # 更多产品XPATH
# more_menu = WebDriverWait(driver=wd, timeout=15).until(EC.visibility_of_element_located((By.XPATH, menu_xpath)))
# ActionChains(driver=wd).move_to_element(move).perform()
sleep(3)  # 仅为能达到悬停效果睡眠，可删除
wd.quit()



